﻿using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;
using System;
using System.Collections.Generic;
using System.Linq;

namespace YangTools.RhinoHelper
{
    class Geometry
    {
        public static TextObject AddTextEntity(string text)
        {
            return AddTextEntity(text, Plane.WorldXY, null, null, false, false, TextJustification.TopLeft);
        }
        public static TextObject AddTextEntity(string text, Plane plane, double? height, Font font, bool bold, bool italic, TextJustification textJustification)
        {
            // 创建文字物件
            var ds = RhinoDoc.ActiveDoc.DimStyles.Current;
            var textEntity = TextEntity.Create(text, plane, ds, false, 0, 0);

            // 设置 高度
            textEntity.TextHeight = (height == null) ? ds.TextHeight : height.Value;

            // 设置 字体
            if (font != null) textEntity.Font = font;

            // 设置 加粗 斜体
            textEntity.SetBold(bold);
            textEntity.SetItalic(italic);

            // 设置对其方式
            textEntity.Justification = textJustification;

            // 添加到rhino中
            var textId = RhinoDoc.ActiveDoc.Objects.Add(textEntity);

            var textObject = RhinoDoc.ActiveDoc.Objects.FindId(textId) as TextObject;
            return textObject;
        }
    }
}
